package tt.com.feesmanager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import tt.com.common.enums.Status;
import tt.com.common.model.DeadProject;
import tt.com.common.util.CommonResult;
import tt.com.common.util.PageUtil;
import tt.com.feesmanager.mapper.DeadprojectMapper;
import tt.com.feesmanager.service.FeesService;

import java.util.List;

@Service
public class FessServiceImpl extends ServiceImpl<DeadprojectMapper,DeadProject> implements FeesService {
    @Override
    public CommonResult showDeadProject(PageUtil pageUtil) {
        IPage<DeadProject> page = new Page<>(pageUtil.getPageIndex(),pageUtil.getPageSize());
        QueryWrapper<DeadProject> queryWrapper = new QueryWrapper<>();
        IPage<DeadProject> page1 = baseMapper.selectPage(page,queryWrapper);
        pageUtil.setTotalSize((int) page1.getTotal());
        pageUtil.setData(page1);
        if (pageUtil==null&&pageUtil.equals("")){
            return CommonResult.buildR(Status.DEFAULT,"数据库内容为空");
        }else
            return CommonResult.buildR(Status.OK,"显示成功",pageUtil);
    }

    @Override
    public CommonResult deleteDeadproject(DeadProject deadProject) {
        DeadProject deadProject1 = baseMapper.selectById(deadProject.getId());
        if (deadProject1==null){
            return CommonResult.buildR(Status.DEFAULT,"没有该数据，无法删除");
        }else if (deadProject.getDataStatus()==1){
            deadProject.setDataStatus(0);
        }else {
            return CommonResult.buildR(Status.OK,"该数据已经删除");
        }
        if (baseMapper.updateById(deadProject)==1){
            return CommonResult.buildR(Status.OK,"该条数据已删除");
        }else {
            return CommonResult.buildR(Status.DEFAULT,"删除失败");
        }
    }

    @Override
    public CommonResult updateDeadProject(DeadProject deadProject) {
        if (deadProject==null){
            return CommonResult.buildR(Status.DEFAULT,"没有该数据，无法修改");
        }else
            baseMapper.updateById(deadProject);
        return CommonResult.buildR(Status.OK,"修改成功");
    }

    @Override
    public CommonResult selectDeadproject(DeadProject deadProject, PageUtil pageUtil) {
        List<DeadProject> list = baseMapper.selectList(null);
        IPage<DeadProject> page = new Page<>(pageUtil.getPageIndex(),pageUtil.getPageSize());
        QueryWrapper<DeadProject> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",deadProject.getId());
        IPage<DeadProject> page1 = baseMapper.selectPage(page,queryWrapper);
        if (page1==null){
            return CommonResult.buildR(Status.DEFAULT,"查询结果为空");
        }else {
            return CommonResult.buildR(Status.OK,"查询成功，已返回查询结果",page1);
        }
    }
}
